package com.workQueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.utils.RabbitMQConnectionUtil;
import org.junit.Test;

public class Publisher {

    public static final String QUEUE_NAME = "work-queue";

    @Test
    public void publish() throws Exception {
        Connection connection = RabbitMQConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        for (int i = 0; i<1000 ; i++) {
            String message = "work queue!" + i;
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("消息"+ i +"发送成功！");
            Thread.sleep(1000);
        }
    }
}